package xyz.jangle.design.flyweight;

import java.util.HashMap;
import java.util.Map;

public class FlyweightFactory {
	
	private Map<String, Flyweight> hashMap = new HashMap<String, Flyweight>();
	
	private static FlyweightFactory factory = new FlyweightFactory();
	
	private FlyweightFactory() {}
	/**
	 * 获取唯一实例
	 * @return
	 */
	public static FlyweightFactory getInstance() {
		return factory;
	}
	
	public Flyweight getFlyweight(String key) {
		if(hashMap.containsKey(key)) {
			return hashMap.get(key);
		}else {
			ConcreteFlyweight flyweight = new ConcreteFlyweight(Integer.valueOf(key));
			hashMap.put(key, flyweight);
			return flyweight;
		}
		
	}
	
	

}
